﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Web.Admin.Page_System
{
    public partial class SystemConfig : Evan.WebUI.ManagerPage
    {
        public string ConfigPath = "~/App_Data/SysConfig/system.config";
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region 读取数据

        /// <summary>
        /// 获取某一节点的所有孩子节点的值
        /// </summary>
        /// <param name="node">要查询的节点</param>
        /// 使用示例
        /// /root/category[@name='Carroit']  查询数据库中的表
        public List<category> GetCategoryList()
        {

            List<category> categoryList = new List<category>();
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(Evan.Common.DirFile.ReadFile(ConfigPath));
            XmlNode xn = xmldoc.SelectSingleNode(string.Format("/root"));
            XmlNodeList nodelist = xn.ChildNodes;  //得到该节点的子节点
            if (nodelist.Count > 0)
            {
                category cate = new category();
                foreach (XmlElement el in nodelist)//读元素值
                {
                    cate = new category();
                    cate.name = el.Attributes["name"].Value;
                    cate.show = Convert.ToInt32(el.Attributes["show"].Value);
                    cate.type = el.Attributes["type"].Value;
                    categoryList.Add(cate);
                }
            }
            return categoryList;
        }

        /// <summary>
        /// 获取某一节点的所有孩子节点的值
        /// </summary>
        /// <param name="node">要查询的节点</param>
        public List<item> GetItemListByCategory(string CategoryName)
        {

            List<item> itemList = new List<item>();
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(Evan.Common.DirFile.ReadFile(ConfigPath));
            XmlNode xn = xmldoc.SelectSingleNode(string.Format("/root/category[@name='{0}']", CategoryName));
            XmlNodeList nodelist = xn.ChildNodes;  //得到该节点的子节点
            if (nodelist.Count > 0)
            {
                item it = new item();
                foreach (XmlElement el in nodelist)//读元素值
                {
                    it = new item();
                    it.name = (el.Attributes["name"].Value);
                    it.show = Convert.ToInt32(el.Attributes["show"].Value);
                    it.title = (el.Attributes["title"].Value);
                    it.value = (el.InnerText);
                    it.notice = (el.Attributes["notice"].Value);
                    itemList.Add(it);
                }
            }
            return itemList;
        }

        #endregion


        #region 
        /// <summary>
        /// 分类
        /// </summary>
        public class category {
            /// <summary>
            /// 分类
            /// </summary>
            public string type { get; set; }
            /// <summary>
            /// 是否显示
            /// </summary>
            public int show { get; set; }
            /// <summary>
            /// 名称
            /// </summary>
            public string name { get; set; }
        }

        /// <summary>
        /// 条目
        /// </summary>
        public class item
        {
            /// <summary>
            /// 标识
            /// </summary>
            public string name { get; set; }
            /// <summary>
            /// 标题
            /// </summary>
            public string title { get; set; }
            /// <summary>
            /// 是否显示
            /// </summary>
            public int show { get; set; }
            /// <summary>
            /// 值
            /// </summary>
            public string value { get; set; }
            /// <summary>
            /// 说明
            /// </summary>
            public string notice { get; set; }
        }
        #endregion



    }
}